home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / c / minigl.lha / MiniGL / demos / smtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-27  |  1.8 KB  |  79 lines

  1. // This demo demonstrates the "Amiga-specific" display features, like
  2. // screenmode callbacks, and access of the back buffer
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <mgl/gl.h>
  7.  
  8. #include <proto/dos.h>          // For Delay()
  9.  
  10. GLboolean ScreenModeCallback(MGLScreenMode *mode)
  11. {
  12.     printf("ModeID: %d\n", mode->id);
  13.     printf("   Size is %d×%d\n", mode->width, mode->height);
  14.     printf("   Depth is %d\n", mode->bit_depth);
  15.     printf("   Name is %s\n", mode->mode_name);
  16.     printf("\n");
  17.     return GL_FALSE;
  18. }
  19.  
  20. GLboolean ScreenModeCallback2(MGLScreenMode *mode)
  21. {
  22.     if (mode->width == 320 && mode->bit_depth==16) return GL_TRUE;
  23.     else return GL_FALSE;
  24. }
  25.  
  26. int main(int argc, char **argv)
  27. {
  28.     GLint id;
  29.     GLint w, h;
  30.     MGLLockInfo li;
  31.  
  32.     MGLInit();
  33.  
  34.     printf("Getting all modes:\n");
  35.     id = mglGetSupportedScreenModes(ScreenModeCallback);
  36.     printf("(Returned id %d)\n",id);
  37.     printf("\n\nTrying to find a mode that satisfies ""Width==320"" and ""bit_depth==16""\n");
  38.  
  39.     id = mglGetSupportedScreenModes(ScreenModeCallback2);
  40.     printf("Returned id is %d\n", id);
  41.  
  42.     if (id == -1 || (argc == 2 && 0 == stricmp(argv[1],"-window")))
  43.     {
  44.         mglChooseWindowMode(GL_TRUE);
  45.     }
  46.  
  47.  
  48.     mglCreateContext(0, 0, 320, 240);
  49.  
  50.     if (mglLockBack(&li))
  51.     {
  52.         glClearColor(0.0, 0.0, 0.0, 0.0);
  53.         glClear(GL_COLOR_BUFFER_BIT);
  54.         glFinish();             // <--- Note this glFinish(); It ensures that the clear operation
  55.                                 //      is really done when we access the back buffer
  56.  
  57.         memset(li.base_address, 0xff, 20);
  58.         mglUnlockDisplay();
  59.         mglSwitchDisplay();
  60.         Delay(100);
  61.  
  62.  
  63.         printf("Display info:\nDimensions:%d×%d×%d\n", li.width, li.height, li.depth);
  64.         printf("Pixel format: %d\n", li.pixel_format);
  65.         printf("Base address: 0x%x\n", li.base_address);
  66.         printf("Pitch: %d\n", li.pitch);
  67.     }
  68.     else
  69.     {
  70.         printf("Unable to lock back buffer\n");
  71.     }
  72.  
  73.     mglDeleteContext();
  74.  
  75.     MGLTerm();
  76.  
  77.     return 0;
  78. }
  79.